﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using VPM.CommonLibrary.Commands;
using VPM.CommonLibrary.ViewModels;

namespace ListViewItemFloatTest
{
    class ListViewItemFloatTestViewModel:ViewModelBase
    {

        private ObservableCollection<Client> _selectedClients;
        private ObservableCollection<Client> _clients;

        public ObservableCollection<Client> Clients
        {
            get
            {
                return _clients;
            }
            set
            {
                _clients = value;
                OnPropertyChanged("Clients");
            }
        }
        public ObservableCollection<Client> SelectedClients 
        {
            get 
            {
                return _selectedClients;
            }
            set 
            {
                _selectedClients = value;
                OnPropertyChanged("SelectedClients");
            } 
        }

        public Client SelectedClient { get; set; }

        public ListViewItemFloatTestViewModel()
        {
            Clients = new ObservableCollection<Client>()
            {
                new Client(){ ClientCode="CL001", ClientName="Lindsay Bluth Fünke"},
                
                new Client(){ ClientCode="CL002", ClientName="Adam Smith"},
                
                new Client(){ ClientCode="CL003", ClientName="Charles Darwin"},
                
                new Client(){ ClientCode="CL004", ClientName="Tom Selleck"},
                
                new Client(){ ClientCode="CL005", ClientName="Jon Skeet"}

            };
            SelectedClients = new ObservableCollection<Client>();
            InitializeCommands();
        }
        #region ExposedCommands
        public ICommand SelectClientCmd { get; protected set; }
        #endregion


        #region Initialization Methods
        private void InitializeCommands()
        {
            this.SelectClientCmd = new RelayCommand(
            (param) =>
            {
                this.SelectClient();
            },
            (param) => { return this.CanSelectClient; }
            );
        }
        #endregion


        #region Command Execution Methods
        private void SelectClient()
        {
            if (SelectedClients.Contains(SelectedClient))
            {
                Clients.Add(new Client { ClientName = SelectedClient.ClientName, ClientCode = SelectedClient.ClientCode });
                SelectedClients.Remove(SelectedClient);
               
            }
            else
            {
                SelectedClients.Add(new Client { ClientName = SelectedClient.ClientName, ClientCode = SelectedClient.ClientCode });
                Clients.Remove(SelectedClient);
               
            }
            

        }
        #endregion


        #region Command Enabling/Disabling Properties
        private bool CanSelectClient
        {
            get
            {
                //insert logic around deciding whether the command can or cannot be executed
                return true;
            }
        }
        #endregion

    }
}
